<?php
include_once('admin_global.php');
bn_include_lib('bn_jquery');
$theme->add_block('body');
$usr=new bn_user();

$cmd=$_POST['cmd'];
$row=new stdclass;
if(isset($cmd))
{
    extract($_POST);    

    if($cmd=='insert_user')
    {
      if($hiden_id=='')
      {
        if(strlen($pass)<5)
        exit($lang['user']['errpass']);
        $code=$usr->insert($user,$pass,$rolenameddl,$mail,$langddl);
        echo $lang[$code];
        die;
      } 
      else
      {
        $usr->update($user,$pass,$rolenameddl,'',$mail,$langddl,$hiden_id);
        die($lang[74]);
      }        
    } 
    if($cmd=='update')
    {
        $row=$usr->Select_all('id',$id)->fetchobj();
        $row=$row[0];
    } 
}

$theme->add_script("$('#hiden_clear').hide()
                    $('#hiden_clear').live('click',function(){
                    $('table tr').removeAttr('style');
                    $('#hiden_id').val('');
                    $(this).hide();   
                    });");
 
$arg=array('cls'=>"$('#hiden_clear').click()");                   
?>
<script>
$('#insert').live('click',function(e){ 
                
                $.post(window.location.href,'cmd=insert_user&'+$('#insert_div :input').serialize(),function(data)
                {
                        alert(data);
                        $('#hiden_clear').click()
                });
                });
</script>
<div id="insert_div">
<input type="hidden" name="hiden_id" id="hiden_id" value="<?php  echo $row->id ?>"/>
<table>
<tr>
	<td><?php echo $lang[1] ?></td>
    <td><input type="text" size="25" autocomplete="on" name="user" id="user" class="input-text" value="<?php echo $row->user ?>"/></td>	
</tr>
<tr>
	<td><?php echo $lang[2] ?></td>
    <td><input type="text" size="25" autocomplete="on" name="pass" id="pass" class="input-text"/></td>	
</tr>
<tr>
	<td><?php echo $lang[48] ?></td>
    <td><?php
	$rn=new bn_rolname;
     $rn->ddl_rolename(array('name' => 'rolenameddl','text'=>'name','value'=>'id','cssclass'=>'select','selected'=>$row->rol));
    ?></td>	
</tr>
<tr>
	<td><?php echo $lang[22] ?></td>
    <td><input type="text" size="25" autocomplete="on" name="mail" id="mail" class="input-text" value="<?php echo $row->mail ?>"/></td>	
</tr>
<tr>
    <td><?php echo $lang[50] ?></td>
    <td><?php echo $lan->lang_list(array('name' => 'langddl','cssclass'=>'select','selected'=>$row->lang)); ?></td>		
</tr>
<tr>
	<td colspan="2"><input type="submit" name="insert" id="insert" value="<?php echo $lang[15] ?>" class="button"/>
    <input type="submit" name="hiden_clear" id="hiden_clear" value="<?php echo $lang[18] ?>" class="button"/></td>
</tr>
</table>
</div>
<?php
$theme->render();
?>